home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / src / srgp_echo_X.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  8.0 KB  |  340 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** INFORMATION ABOUT THE LOW-LEVEL ECHOING DRIVERS
  5.  
  6. SRGP__initEchoModule ()
  7.    Must be called once, during initialization.
  8.    The echo-attribute globals must have already been given
  9.       default initial values!
  10.  
  11. SRGP__updateLocatorRubberAnchor ()
  12.    Acesses current locator rubber anchor from globals.
  13.    May be called whether rubber echo is active or not.
  14.  
  15. SRGP__enableLocatorRubberEcho ()
  16.    Accesses current locator measure info from global variables.
  17.    May be called carelessly:
  18.       1) Will not re-enable if already enabled
  19.       2) Will refuse to enable echo for a device that is:
  20.       A) not active currently, and 
  21.       B) not in a state for which echo is desired
  22.  
  23. SRGP__updateLocatorRubberEcho ()
  24.    Accesses current locator measure info from global variables.
  25.    May be called carelessly:
  26.       Will not update if device is currently disabled.
  27.  
  28. SRGP__disableLocatorRubberEcho ()
  29.    May be called carelessly:
  30.       Will not re-disable if already disabled
  31.  
  32.  
  33. SRGP__updateLocatorCursorShape ()
  34.    May be called whether or not the cursor echo is active.
  35.  
  36. SRGP__enableLocatorCursorEcho ()
  37. SRGP__disableLocatorCursorEcho ()
  38.       May be called carelessly.
  39.  
  40. SRGP__updateRawCursorPosition ()
  41.       Accesses cur_locator_measure from global variables.
  42.       Informs the underlying graphics package of the desired "cursor warp".
  43.       Automatically updates any type of locator echo: cursor or rubber.
  44.  
  45.  
  46. SRGP__updateKeyboardEchoAttributes ()
  47.    May be called whether or not key echo is active.
  48.    Obtains attributes from global variables.
  49.  
  50. SRGP__enableKeyboardEcho ()
  51. SRGP__updateKeyboardEcho ()
  52. SRGP__disableKeyboardEcho ()
  53.       Similar to above: may be called carelessly.
  54.  
  55. **/
  56.  
  57.  
  58. /* FOR LOCATOR ECHO */
  59. static boolean locator_echo_is_active=FALSE;
  60. static GC echo__locator_gc;
  61. static Cursor echo__locator_cursor_shape;
  62. static point echo__locator_rubber_anchor, echo__locator_previous_position;
  63.      /* IN X, not SRGP, COORDS */
  64.  
  65. /* FOR KEYBOARD ECHO */
  66. static boolean keyboard_echo_is_active=FALSE;
  67. static GC echo__keyboard_gc;
  68. static XFontStruct *echo__keyboard_font;
  69. static int
  70.     /* THE SCREEN LOCATION OF THE ECHO IN X's COORDINATE SYSTEM!
  71.      */
  72.     echo__keyboard_left,   /* X */
  73.     echo__keyboard_origin;  /* Y */
  74. static XCharStruct echo__keyboard_overall;
  75. static int font_ascent, font_descent;
  76.  
  77.  
  78.  
  79. void
  80. SRGP__initEchoModule ()
  81. {
  82.    /* CREATE THE TWO GC's. */
  83.    echo__keyboard_gc = XCreateGC (srgpx__display, srgpx__screenwin, 0L, NULL);
  84.    echo__locator_gc = XCreateGC (srgpx__display, srgpx__screenwin, 0L, NULL);
  85.  
  86.    /* INITIALIZE KEYBOARD GC: font, color, origin */
  87.    SRGP__updateKeyboardEchoAttributes ();
  88.  
  89.    /* DEFAULT LOCATOR-ECHO RUBBER ANCHOR (same as keyboard echo). */
  90.    echo__locator_rubber_anchor =
  91.       SRGP_defPoint(echo__keyboard_left, echo__keyboard_origin);
  92.  
  93.    /* INITIALIZE LOCATOR RUBBER-ECHO GC: write-mode XOR. */
  94.    if (XWHITE == 0)
  95.        XSetFunction (srgpx__display, echo__locator_gc, GXxor);
  96.    else
  97.        XSetFunction(srgpx__display, echo__locator_gc, GXequiv);
  98.    XSetForeground (srgpx__display, echo__locator_gc, XBLACK);
  99. }
  100.  
  101.  
  102.  
  103. static void
  104. ToggleRubberRect ()
  105. /* DRAWS BETWEEN rubber_anchor AND previous_position */
  106. {
  107.    int tlx, tly, width, height;
  108.  
  109.    if (echo__locator_rubber_anchor.x < echo__locator_previous_position.x) {
  110.       tlx = echo__locator_rubber_anchor.x;
  111.       width = echo__locator_previous_position.x - tlx + 1;
  112.    }
  113.    else {
  114.       tlx = echo__locator_previous_position.x;
  115.       width = echo__locator_rubber_anchor.x - tlx + 1;
  116.    }
  117.  
  118.    if (echo__locator_rubber_anchor.y < echo__locator_previous_position.y) {
  119.       tly = echo__locator_rubber_anchor.y;
  120.       height = echo__locator_previous_position.y - tly + 1;
  121.    }
  122.    else {
  123.       tly = echo__locator_previous_position.y;
  124.       height = echo__locator_rubber_anchor.y - tly + 1;
  125.    }
  126.  
  127.    XDrawRectangle (srgpx__display, srgpx__screenwin,
  128.            echo__locator_gc,
  129.            tlx,tly,  width, height);
  130. }
  131.  
  132.      
  133. static void
  134. ToggleRubberLine()
  135. /* DRAWS BETWEEN rubber_anchor AND previous_position */
  136. {
  137.    XDrawLine (srgpx__display, srgpx__screenwin,
  138.           echo__locator_gc,
  139.           ExplodePt(echo__locator_previous_position),
  140.           ExplodePt(echo__locator_rubber_anchor));
  141. }
  142.  
  143.  
  144. static void
  145. ToggleRubberEcho()
  146. {
  147.    if (srgp__cur_locator_echo_type == RUBBER_RECT) 
  148.       ToggleRubberRect();
  149.    else
  150.       ToggleRubberLine();
  151. }
  152.  
  153.  
  154. void
  155. SRGP__enableLocatorRubberEcho ()
  156. {
  157.    if ( ! locator_echo_is_active)
  158.       if (srgp__cur_mode[LOCATOR] != INACTIVE) 
  159.      if (srgp__cur_locator_echo_type > CURSOR) {
  160.         echo__locator_previous_position =
  161.            SRGP_defPoint 
  162.           (srgp__cur_locator_measure.position.x, 
  163.           SCREENFIXED(srgp__cur_locator_measure.position.y));
  164.         echo__locator_rubber_anchor =
  165.            SRGP_defPoint
  166.           (srgp__cur_locator_echo_anchor.x,
  167.            SCREENFIXED(srgp__cur_locator_echo_anchor.y));
  168.         locator_echo_is_active = TRUE;
  169.         ToggleRubberEcho();
  170.      }
  171. }
  172.  
  173.  
  174. void
  175. SRGP__disableLocatorRubberEcho()
  176. {
  177.    if (locator_echo_is_active) {
  178.       ToggleRubberEcho();
  179.       locator_echo_is_active = FALSE;
  180.    }
  181. }
  182.  
  183.  
  184. void
  185. SRGP__updateLocatorRubberEcho ()
  186. {
  187.    if (locator_echo_is_active) {
  188.       ToggleRubberEcho();
  189.       echo__locator_previous_position =
  190.      SRGP_defPoint (srgp__cur_Xcursor_x, srgp__cur_Xcursor_y);
  191.       ToggleRubberEcho();
  192.    }      
  193. }
  194.    
  195.  
  196.  
  197. void
  198. SRGP__updateLocatorRubberAnchor ()
  199. {
  200.    if (locator_echo_is_active)
  201.       ToggleRubberEcho();
  202.  
  203.    echo__locator_rubber_anchor =
  204.       SRGP_defPoint
  205.      (srgp__cur_locator_echo_anchor.x,
  206.       SCREENFIXED(srgp__cur_locator_echo_anchor.y));
  207.  
  208.    if (locator_echo_is_active)
  209.       ToggleRubberEcho();
  210. }
  211.  
  212.  
  213.  
  214. void
  215. SRGP__enableLocatorCursorEcho ()
  216. {
  217.    if (srgp__cur_mode[LOCATOR] != INACTIVE) 
  218.       if (srgp__cur_locator_echo_type == CURSOR) {
  219.      XDefineCursor (srgpx__display, srgpx__screenwin, 
  220.             echo__locator_cursor_shape);
  221.       }
  222. }
  223.  
  224.  
  225. void
  226. SRGP__disableLocatorCursorEcho ()
  227.    XUndefineCursor (srgpx__display, srgpx__screenwin);
  228. }
  229.  
  230.  
  231. void
  232. SRGP__updateLocatorCursorShape ()
  233. {
  234.    echo__locator_cursor_shape = srgp__cursorTable[srgp__cur_cursor];
  235.    SRGP__enableLocatorCursorEcho ();
  236. }
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. /** KEYBOARD ECHO **/
  244.  
  245. static void
  246. DrawText ()
  247. {
  248.    int direction;
  249.  
  250.    XDrawImageString (srgpx__display, srgpx__screenwin, echo__keyboard_gc,
  251.              echo__keyboard_left, echo__keyboard_origin,
  252.              srgp__cur_keyboard_measure.buffer, 
  253.              srgp__cur_keyboard_measure_length);
  254.    XTextExtents (echo__keyboard_font,
  255.            srgp__cur_keyboard_measure.buffer, 
  256.            srgp__cur_keyboard_measure_length,    
  257.           &direction, &font_ascent, &font_descent,
  258.           &echo__keyboard_overall);
  259.    XFillRectangle (srgpx__display, srgpx__screenwin, echo__keyboard_gc,
  260.              echo__keyboard_left + echo__keyboard_overall.width + 2,
  261.             echo__keyboard_origin - font_ascent,
  262.             7, font_ascent + font_descent);
  263.   }
  264.  
  265.  
  266. static void
  267. EraseText()
  268. {
  269.    XClearArea (srgpx__display, srgpx__screenwin,
  270.            echo__keyboard_left, 
  271.            echo__keyboard_origin - font_ascent,
  272.            echo__keyboard_overall.width + 9, 
  273.             font_ascent + font_descent,
  274.            FALSE);
  275. }
  276.  
  277.  
  278. void
  279. SRGP__enableKeyboardEcho ()
  280. {
  281.    if ( ! keyboard_echo_is_active)
  282.       if (srgp__cur_mode[KEYBOARD] != INACTIVE) 
  283.      if (srgp__cur_keyboard_processing_mode == EDIT) {
  284.         keyboard_echo_is_active = TRUE;
  285.         DrawText();
  286.      }
  287. }
  288.  
  289.  
  290. void
  291. SRGP__disableKeyboardEcho ()
  292. {
  293.    if (keyboard_echo_is_active) {
  294.       EraseText();
  295.       keyboard_echo_is_active = FALSE;
  296.    }
  297. }
  298.  
  299.  
  300. void
  301. SRGP__updateKeyboardEcho ()
  302. {
  303.    if (keyboard_echo_is_active) {
  304.       EraseText();
  305.       DrawText();
  306.    }
  307. }
  308.  
  309.  
  310. void
  311. SRGP__updateKeyboardEchoAttributes ()
  312. {
  313.    if (keyboard_echo_is_active) {
  314.       EraseText();
  315.    }
  316.  
  317.    echo__keyboard_left = srgp__cur_keyboard_echo_origin.x;
  318.    echo__keyboard_origin = SCREENFIXED(srgp__cur_keyboard_echo_origin.y);
  319.  
  320.    XSetForeground (srgpx__display, echo__keyboard_gc, 
  321.            XCOLOR(COLORINDEX(srgp__cur_keyboard_echo_color)));
  322.    XSetBackground (srgpx__display, echo__keyboard_gc, 
  323.            XCOLOR(COLORINDEX(SRGP_WHITE)));
  324.  
  325.    XSetFont (srgpx__display, echo__keyboard_gc, 
  326.          (echo__keyboard_font =
  327.             srgp__fontTable[srgp__cur_keyboard_echo_font])->fid);
  328.  
  329.    if (keyboard_echo_is_active) {
  330.       DrawText();
  331.    }
  332. }
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.